package com.xm.starter;

import com.xm.core.ClassScanner;
import com.xm.web.handler.HandlerManager;
import com.xm.web.server.TomcatServer;
import org.apache.catalina.LifecycleException;

import java.io.IOException;
import java.util.List;

public class MiniApplication {
    public static void run(Class<?> cls, String[] args) {
        System.out.println("Hello mini-spring," + cls.getName());

        TomcatServer tomcatServer = new TomcatServer(args);
        try {
            tomcatServer.startServer();
            // 通过类加载器实现类的扫描
            List<Class<?>> classList = ClassScanner.scanClasses(cls.getPackage().getName());
            // 通过反射实现 mappingHandler
            HandlerManager.resolveMappingHandler(classList);

//            classList.forEach(it -> System.out.println(it.getName()));
        } catch (LifecycleException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
